<!DOCTYPE html>
<!--suppress ALL-->
<html lang="zh" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<th:block th:fragment="layer">
    <script th:src="@{/lib/layer/layer.js}"></script>
</th:block>

<th:block th:fragment="md(id)">
    <script th:src="@{/lib/editor.md/editormd.min.js}"></script>
    <script type="text/javascript">
        $(function () {
            editormd("[[${id}]]", {
                width: "90%",
                height: 640,
                syncScrolling: "single",
                path: "[[@{/lib/editor.md/lib/}]]"
            });
        });
    </script>
</th:block>

<script th:fragment="semantic" src="http://cdn.bootcdn.net/ajax/libs/semantic-ui/2.4.1/semantic.js"></script>

<th:block th:fragment="common">
    <script th:if="${msg}" th:inline="javascript">
        alert([[${msg}]]);
    </script>
    <script src="http://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="http://cdn.bootcdn.net/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
    <script src="http://cdn.bootcdn.net/ajax/libs/vue/3.1.5/vue.global.prod.min.js"></script>
    <script src="http://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <script>
const root_path = "[[${ #httpServletRequest.getServerName() + ':' + #request.getServerPort()  + #request.getContextPath() } ]]"

function json2form(json) {
    let ks = Object.keys(json), i = 0;
    ks.forEach((ele, i, arr) => arr[i] += "=" + json[arr[i]]);
    return ks.join("&");
}

function chain(option) {
    return new Promise((resolve, reject) => {
        axios(option).then(r => resolve(r.data)).catch(e => reject(e));
    });
}

        /*
       形如
       var res=chain({}).then(
           data=>{
               return chain({});
           }
       ).then(
           data=>{
               return chain({});
           }
       ).then(
           data=>{
               return result;
           }
       )
       */

        function form_api(url, callback, json, post) {
            if (post) return json_api(url, callback, json2form(json), true);
            return json_api(url, callback, json);
        }

        function json_api(url, callback = a => {
        }, json = {}, post = false) {
            if (post) return axios.post(url, json).then(r => callback(r.data));
            return axios.get(url, {params: json}).then(r => callback(r.data));
        }
    </script>
</th:block>


<th:block th:fragment="tools">
    <script>
        function guid() {
            function S4() {
                return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            }

            return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
        }
    </script>
</th:block>

</body>
</html>